<?php

/*
 * +----------------------------------------------------------------------
 * 作 者: 蔡建祥 
 * +----------------------------------------------------------------------
 * 创建日期：2021-04-21
 * ------------------------------------------------------------------------
 * 文件描述：角色管理
 * ------------------------------------------------------------------------
 * 升级记录：
 * ------------------------------------------------------------------------
 */
class LeaderCheckAction extends CommonAction
{

    /**
     * 查询角色信息
     */
    public function index()
    {
        $model = new MediaModel();
        
        // 条件检索
        if (! empty($_REQUEST['search_keyword'])) {
            $where['name|get_user_name(operator)|rs'] = array(
                'like',
                '%' . $this->_request('search_keyword') . '%'
            );
        }
        
        // 分页处理
        import('ORG.Util.Page'); // 导入分页类
        $count = $model->where($where)->count(); // 查询满足要求的总记录数
        $p = $this->_page($model, 'update_date'); // 分页所需信息
        $page = new Page($count, $p['listRows']); // 实例化分页类 传入总记录数和每页显示的记录数
        $data = $model->field("id,
 								path,
								name,
 								rs,
							    audit,
 								get_user_name(operator) operator,
 							 	update_date")
            ->where($where)
            ->order("`" . $p['order'] . "` " . $p['sort'])
            ->limit($page->firstRow . ', ' . $page->listRows)
            ->select();
        $this->assign('data', $data);
        $show = $page->show(); // 分页显示输出
        $this->assign('show', $show); // 绑定分页显示字符串
        $this->display();
    }
    public function audit(){
    	$model = new MediaModel();
    	$data = $model->where("id = '".$_REQUEST['id']."'")->find();
    	$this->assign('list', $data);
    	$this->display();
    }
    /**
     * 将审核后的信息更新到数据库
     */
    public function update_audit() {
    	$roomid = $_REQUEST['id'];
    	$model = new MediaModel();
    	if(false !== $model->where("id = '".$roomid."'")->setField('audit','b')){
    		$this->success('审核通过',  __APP__.'?g=Admin&m=LeaderCheck&a=index');
    	}
    }
    /**
     * 批量审核、取消审核
     */
    public function delete() {
    	//处理传递过来的id串
    	$ids = $_REQUEST['ids'];
    	$id = implode("','", $ids);	//用','分割id数组，以便于拼装sql语句
    	$id = "'".$id."'";
    	
    	$model = new MediaModel();
    	$model->startTrans();
    	if(false !== $model->where('id in('.$id.')')->setField('audit','a')) {
    		$model->commit();
    		redirect($_SERVER['HTTP_REFERER']);
    	} else {
    		$model->rollback();
    		$this->error('取消审核失败！');
    	}
    }
    /**
     * 批量审核、取消审核
     */
    public function manage() {
    	//处理传递过来的id串
    	$ids = $_REQUEST['ids'];
    	$id = implode("','", $ids);	//用','分割id数组，以便于拼装sql语句
    	$id = "'".$id."'";
    	
    	$model = new MediaModel();
    	$model->startTrans();
    	
    	//根据操作类型执行相应的操作
    	$op = $_REQUEST['op'];
    	if($op == 'audits'){
    		if(false !== $model->where('id in('.$id.')')->setField('audit','b')) {
    			$model->commit();
    			redirect($_SERVER['HTTP_REFERER']);
    		} else {
    			$model->rollback();
    			$this->error('审核失败！');
    		}
    	} elseif($op == 'cancel_audit'){
    		if(false !== $model->where('id in('.$id.')')->setField('audit','a')) {
    			$model->commit();
    			redirect($_SERVER['HTTP_REFERER']);
    		} else {
    			$model->rollback();
    			$this->error('取消审核失败！');
    		}
    	} else {
    		$model->rollback();
    		$this->error('未知操作类型！');
    	}
    }
}
?>